
import { observable, action } from 'mobx';
import { Button } from 'antd';

import BaseListStore from './common/BaseListStore';
import * as API_TODO from '../apis/todoApi';
import * as API_MONITOR from "../apis/odocApi";
//import * as ODOC_LABEL from '../constants/label'

/**
 * 待办公文页面 数据对象
 */
export default class DoStore extends BaseListStore {

  @observable showBatchBtn = true;
  @action
  setShowBatchBtn = showBatchBtn => {
    this.showBatchBtn = showBatchBtn;
  }

  constructor() {
    super();

    this.setTopTitle(this.getLabel2(507087, "已办公文"));

    //this.API_CONDITION = "/api/odoc/odocTodoList/getCondition";
    //this.API_DATALIST = "/api/odoc/odocTodoList/getTodoList";
    this.API_TABCOUNT = "/api/odoc/odocTodoList/getTodoCount";

    //this.searchStore.setConditionApi(this.API_CONDITION);
    //this.searchStore.setListApi(this.API_DATALIST);
    //this.searchStore.setDoSe(this.doSearch);
    //this.searchStore.setBuildCon(this.buildCondition);

  }



  getSearchsBaseValue() {
    return this.searchStore.form.getFormParams().requestname;
  }

  setSearchsBaseValue(v) {
    this.searchStore.form.updateFields({
      requestname: {
        value: v
      }
    });
    this.searchStore.isSearched();
  }

  getTopBtns() {
    const btns = [
      <Button type='ghost' disabled={this.showBatchBtn}>{this.getLabel2('17598', "批量提交")}</Button>
    ];

    return (btns);
  }

  handleSelectedRowsChange(selectedRows) {
    this.setSelectedRows(selectedRows);
    if (this.selectedRows.length > 0) {
      this.setShowBatchBtn(false);
    } else {
      this.setShowBatchBtn(true);
    }
  }

  doSearch(params = {}) {
    let param_todoList = this.searchStore.getFormParams();
    Object.assign(param_todoList, param_todoList, this.searchStore.otherSearchParams, { iscomplete: 1 });

    API_TODO.getTodoList(param_todoList).then(data => {
      this.searchStore.tableStore.getDatas(data.generateParams.sessionkey, params.current || 1);
      //this.dataKey = data.generateParams.sessionkey;
      //this.loading = false;
    });
    this.searchStore.setShowSearchAd(false);
    return this;
  }

  buildSearchCondition(params = {}) {
    Object.assign(params, params, this.searchStore.otherSearchParams, { iscomplete: 1 });
    API_TODO.getCondition(params).then(data => {
      this.searchStore.setSearchCondition(data);
      const conditioninfo = data.conditions || data.condition;
      this.searchStore.form.initFormFields(conditioninfo);
      this.doSearch();
    });
  }

  resetForm() {
    this.searchStore.resetSearchForm();
    //this.searchStore.form.resetForm();
    this.setSearchsBaseValue(" ");
    //this.searchStore.isSearched();

  }

  getColumns = (columns) => {
    let newColumns = columns.map(column => {
      if (column.dataIndex == "odoctype") {
        return {
          ...column, render: (text, record) => {
            return (<p class="wea-odoctype-labelp" title={record.odoctypespan}>{record.odoctypespan}</p>);
          }
        }
      } else {
        return column;
      }
    });

    return newColumns;
  }

  //构建tab页
  buildTabs() {
    if (this.API_TABCOUNT == '') {
      return;
    }
    API_MONITOR.flexibleCallApi(this.API_TABCOUNT, { iscomplete: 1 }).then(data => {
      let tabArr = data.datalist;
      let tabs = [];
      let tabsCount = {};
      tabArr.forEach(function (element) {
        let tab = {
          color: '#000000',
          showcount: true,
          groupid: element.officalType,
          title: element.title,
          viewcondition: element.officalType
        }
        tabs.push(tab);
        tabsCount[element.officalType] = element.count;
      });
      this.setTabs(tabs);
      this.setTabsCount(tabsCount);
    });
  }


}